<?php

namespace app\api\controller\Notice;
use app\api\controller\Common;
use app\api\Logic\Article\ArticleLogic;
use app\api\Logic\CommonLogic;
use app\api\Logic\Notice\NoticeLogic;
use think\Db;

/**
 * 通知
 */
class Notice extends Common
{
    protected $noNeedLogin = ['*'];

    protected $commonLogic;
    protected $noticeLogic;

    public function _initialize()
    {
        parent::_initialize();

        $this->noticeLogic = new NoticeLogic();
        $this->articleLogic = new ArticleLogic();
        $this->commonLogic = new CommonLogic();
    }

    /**
     * 获取通知首页数据
     *
     */
    public function getNoticeIndex()
    {
        if ($this->request->isPost()) {
            $param = $this->request->param();
            //验证数据
            $param = $this->verifyData($param);

            $list = $this->noticeLogic->getNoticeIndex($param);
            $this->success('查询成功',$list);
        }
        $this->error('请求错误');
    }

    /**
     * 获取提醒消息列表
     *
     */
    public function getRemindNoticeList()
    {
        if ($this->request->isPost()) {
            $param = $this->request->param();
            //验证数据
            $param = $this->verifyData($param);

            $list = $this->noticeLogic->getNoticeList($param,1);
            $this->success('查询成功',$list);
        }
        $this->error('请求错误');
    }

    /**
     * 获取互动消息列表
     *
     */
    public function getInteractNoticeList()
    {
        if ($this->request->isPost()) {
            $param = $this->request->param();
            //验证数据
            $param = $this->verifyData($param);

            $list = $this->noticeLogic->getNoticeList($param,2);
            $this->success('查询成功',$list);
        }
        $this->error('请求错误');
    }

    /**
     * 消息已读
     *
     * @return void
     */
    public function readNotice()
    {
        if ($this->request->isPost()) {
            $param = $this->request->param();
            //验证数据
            $param = $this->verifyData($param);
            if(!$param['ids'] || !$param['type']){
                $this->error('参数错误');
            }
            $res = $this->noticeLogic->readNotice($param['ids'],$param['user_id'],$param['type']);
            if($res){
                $this->success('操作成功');
            }
        }
        $this->error('请求错误');
    }

}
